import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/routes/tab_home/view/xindong_user_card_cell.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';
import 'package:xindong/widgets/container/xindong_getx_builder_container.dart';
import 'package:xindong/widgets/container/xindong_home_container.dart';

import 'controller/xindong_pipei_vm.dart';

class XinDongPiPeiYeMian extends StatefulWidget {
  const XinDongPiPeiYeMian({super.key});

  @override
  State<XinDongPiPeiYeMian> createState() => _XinDongPiPeiYeMianState();
}

class _XinDongPiPeiYeMianState extends State<XinDongPiPeiYeMian> with AutomaticKeepAliveClientMixin {
  final controller = Get.put(XinDongPiPeiVM());

  // 避免状态重置
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return XinDongHomeBackgroundView(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: XinDongAppBar(
          "",
          leading: const SizedBox(),
          leadingWidth: kPaddingValue,
          elevation: 0.0,
          backgroundColor: Colors.transparent,
          titleView: const Row(
            children: [
              Text(
                "速配",
                style: TextStyle(fontSize: kTitleFontSize, fontWeight: FontWeight.w500, color: DZColors.titleColor),
              )
            ],
          ),
        ),
        body: XinDongGetBuilder<XinDongPiPeiVM>(builder: (viewClass) {
          return XinDongRefreshContainer(
            viewClass: viewClass,
            child: XinDongEmptyContainer(
              dataList: viewClass.dataList,
              emptyTips: "暂无速配",
              child: GridView.builder(
                padding: const EdgeInsets.fromLTRB(kPaddingValue, 8, kPaddingValue, 8),
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  crossAxisSpacing: 11.0, //水平间距
                  mainAxisSpacing: 11.0, //垂直间距
                  childAspectRatio: 166.0 / 202, //子Widget宽高比例
                ),
                itemCount: viewClass.dataList?.length ?? 0,
                itemBuilder: (BuildContext context, int index) {
                  final model = viewClass.dataList![index];
                  return XinDongUserCardCell(model: model);
                },
              ),
            ),
          );
        }),
      ),
    );
  }
}
